#include <iostream>
#include <string>

using namespace std;

int main(int argc, char const *argv[])
{
    //字符串赋值的方式
    string str_1 = "hello";
    string str_2("hello");
    string str_3(str_2);
    string str_4(10  , 'a');

    cout << "str_1 = " << str_1 << endl;
    cout << "str_2 = " << str_2 << endl;
    cout << "str_3 = " << str_3 << endl;
    cout << "str_4 = " << str_4 << endl;

    //字符串拼接的方式
    str_4 = str_1 + str_2;
    cout << "str_4 = " << str_4 << endl;

    str_4.append("张三");
    cout << "str_4 = " << str_4 << endl;
    str_4.append(10 , 'a');
    cout << "str_4 = " << str_4 << endl;

    //字符串的查找 替换
    size_t pos = str_4.find("张三");//查找
    cout << " 张三在 " << pos << " 的位置" << endl;
    str_4.replace(pos , 6 , "李四");

    cout << "str_4 = " << str_4 << endl;

    //字符串 存取
    char ch_1 = str_1[0];
    char ch_2 = str_1.at(1);

    cout << "str_1[0] = " << ch_1 << "     str_1.at[1] = " << ch_2 << endl;

    //字符串的插入
    str_4.insert(16,"真帅");

    cout << "str_4 = " << str_4 << endl;

    //字符串的删除
    str_4.erase(16,6);
    cout << "str_4 = " << str_4 << endl;

    //字符串的清空
    str_4.clear();
    cout << "str_4 = " << str_4 << endl;

    //字符串的转换 C风格 转 C++

    //C++ 转 C风格
    const char * str_c = str_1.c_str();
    cout << "str_c = " << str_c << endl;

    //C 转 C++
    //和前面赋值一样 直接使用即可

    return 0;
}
